home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 276_01 / az80.h < prev    next >
C/C++ Source or Header  |  1989-10-01  |  12KB  |  432 lines

  1. /*
  2.     HEADER:        CUG276;
  3.     TITLE:        Z-80 Cross-Assembler (Portable);
  4.     FILENAME:    AZ80.H;
  5.     VERSION:    0.1;
  6.     DATE:        08/27/1988;
  7.  
  8.     DESCRIPTION:    "This program lets you use your computer to assemble
  9.             code for the Z-80 and NSC800 families of
  10.             microprocessors.  The program is written in portable C
  11.             rather than BDS C.  All assembler features are
  12.             supported except relocation, linkage, and macros.";
  13.  
  14.     KEYWORDS:    Software Development, Assemblers, Cross-Assemblers,
  15.             Zilog, Z-80, NSC800;
  16.  
  17.     SYSTEM:        CP/M-80, CP/M-86, HP-UX, MSDOS, PCDOS, QNIX;
  18.     COMPILERS:    Aztec C86, Aztec CII, CI-C86, Eco-C, Eco-C88, HP-UX,
  19.             Lattice C, Microsoft C,    QNIX C;
  20.  
  21.     WARNINGS:    "This program is written in as portable C as possible.
  22.             A port to BDS C would be extremely difficult.  A port
  23.             to Toolworks C is untried."
  24.  
  25.     AUTHORS:    William C. Colley III;
  26. */
  27.  
  28. /*
  29.               Z-80 Cross-Assembler in Portable C
  30.  
  31.         Copyright (c) 1986-1988 William C. Colley, III
  32.  
  33. Revision History:
  34.  
  35. Ver    Date        Description
  36.  
  37. 0.0    JUNE 1987    Derived from my S-6 cross-assembler.  WCC3.
  38.  
  39. 0.1    AUG 1988    Fixed a bug in the command line parser that puts it
  40.             into a VERY long loop if the user types a command line
  41.             like "AZ80 FILE.ASM -L".  WCC3 per Alex Cameron.
  42.  
  43. This header file contains the global constants and data type definitions for
  44. all modules of the cross-assembler.  This also seems a good place to put the
  45. compilation and linkage instructions for the animal.  This list currently
  46. includes the following compilers:
  47.  
  48.         Compiler Name        Op. Sys.    Processor
  49.  
  50.     1)  Aztec C86            CP/M-86        8086, 8088
  51.                     MSDOS/PCDOS
  52.  
  53.     2)  AZTEC C II            CP/M-80        8080, Z-80
  54.  
  55.     3)  Computer Innovations C86    MSDOS/PCDOS    8086, 8088
  56.  
  57.     4)  Eco-C            CP/M-80        Z-80
  58.  
  59.     5)  Eco-C88            MSDOS/PCDOS    8086, 8088
  60.  
  61.     6)  HP C            HP-UX        68000
  62.  
  63.     7)  Lattice C            MSDOS/PCDOS    8086, 8088
  64.  
  65.     8)  Microsoft C            MSDOS/PCDOS    8086, 8088
  66.  
  67.     9)  QNIX C            QNIX        8086, 8088
  68.  
  69. Further additions will be made to the list as users feed the information to
  70. me.  This particularly applies to UNIX and IBM-PC compilers.
  71.  
  72. Compile-assemble-link instructions for this program under various compilers
  73. and operating systems:
  74.  
  75.     1)    Aztec C86:
  76.  
  77.     A)  Uncomment out the "#define AZTEC_C 1" line and comment out all
  78.         other compiler names in AZ80.H.
  79.  
  80.     B)  Assuming that all files are on drive A:, run the following
  81.         sequence of command lines:
  82.  
  83.         A>cc az80
  84.         A>cc az80eval
  85.         A>cc az80util
  86.         A>ln az80.o az80eval.o az80util.o -lc
  87.         A>era az80*.o
  88.  
  89.     2)  Aztec CII (version 1.06B):
  90.  
  91.     A)  Uncomment out the "#define AZTEC_C 1" line and comment out all
  92.         other compiler names in AZ80.H.
  93.  
  94.     B)  Assuming the C compiler is called "CC.COM" and all files are
  95.         on drive A:, run the following sequence of command lines:
  96.  
  97.         A>cc az80
  98.         A>as -zap az80
  99.         A>cc az80eval
  100.         A>as -zap az80eval
  101.         A>cc az80util
  102.         A>as -zap az80util
  103.         A>ln az80.o az80eval.o az80util.o -lc
  104.         A>era az80*.o
  105.  
  106.     3)  Computer Innovations C86:
  107.  
  108.     A)  Uncomment out the "#define CI_C86 1" line and comment out all
  109.         other compiler names in AZ80.H.
  110.  
  111.     B)  Compile the files AZ80.C, AZ80EVAL.C, and AZ80UTIL.C.  Link
  112.         according to instructions that come with the compiler.
  113.  
  114.     4)  Eco-C (CP/M-80 version 3.10):
  115.  
  116.     A)  Uncomment out the "#define ECO_C 1" line and comment out all
  117.         other compiler names in AZ80.H.
  118.  
  119.     B)  Assuming all files are on drive A:, run the following sequence of
  120.         command lines:
  121.  
  122.         A>cp az80 -i -m
  123.         A>cp az80eval -i -m
  124.         A>cp az80util -i -m
  125.         A>l80 az80,az80eval,az80util,az80/n/e
  126.         A>era az80*.mac
  127.         A>era az80*.rel
  128.  
  129.     5)  Eco-C88:
  130.  
  131.     A)  Uncomment out the "#define ECO_C 1" line and comment out all
  132.         other compiler names in AZ80.H.
  133.  
  134.     B)  Compile the files AZ80.C, AZ80EVAL.C, and AZ80UTIL.C.  Link
  135.         according to instructions that come with the compiler.
  136.  
  137.     6)  HP-UX (a UNIX look-alike running on an HP-9000 Series 200/500,
  138.     68000-based machine):
  139.  
  140.     A)  Uncomment out the "#define HP_UX 1" line and comment out all
  141.         other compiler names in AZ80.H.
  142.  
  143.     B)  Run the following command line:
  144.  
  145.         . cc az80.c az80eval.c az80util.c
  146.  
  147.     7)  Lattice C:
  148.  
  149.     A)  Uncomment out the "#define LATTICE_C 1" line and comment out all
  150.         other compiler names in AZ80.H.
  151.  
  152.     B)  Compile the files AZ80.C, AZ80EVAL.C, and AZ80UTIL.C.  Link
  153.         according to instructions that come with the compiler.
  154.  
  155.     8)  Microsoft C (version 3.00):
  156.  
  157.     A)  Uncomment out the "#define MICROSOFT_C 1" line and comment out
  158.         all other compiler names in AZ80.H.
  159.  
  160.     B)  Run the following command line:
  161.  
  162.         C>cl az80.c az80eval.c az80util.c
  163.  
  164.     9)    QNIX C:
  165.  
  166.     A)  Uncomment out the "#define QNIX 1" line and comment out all other
  167.         compiler names in AZ80.H.
  168.  
  169.     B)  Run the following command line:
  170.  
  171.         . cc az80.c az80eval.c az80util.c
  172.  
  173. Note that, under CP/M-80, you can't re-execute a core image from a previous
  174. assembly run with the "@.COM" trick.  This technique is incompatible with the
  175. Aztec CII compiler, so I didn't bother to support it at all.
  176. */
  177.  
  178. #include <stdio.h>
  179.  
  180. /*  Comment out all but the line containing the name of your compiler:    */
  181.  
  182. #define        AZTEC_C        1
  183. /* #define    CI_C86        1                    */
  184. /* #define    ECO_C        1                    */
  185. /* #define    HP_UX        1                    */
  186. /* #define    LATTICE_C    1                    */
  187. /* #define    MICROSOFT_C    1                    */
  188. /* #define    QNIX        1                    */
  189.  
  190. /*  Compiler dependencies:                        */
  191.  
  192. #ifdef    AZTEC_C
  193. #define    getc(f)        agetc(f)
  194. #define    putc(c,f)    aputc(c,f)
  195. #endif
  196.  
  197. #ifndef    ECO_C
  198. #define    FALSE        0
  199. #define    TRUE        (!0)
  200. #endif
  201.  
  202. #ifdef    LATTICE_C
  203. #define    void        int
  204. #endif
  205.  
  206. #ifdef    QNIX
  207. #define    fprintf        tfprintf
  208. #define    printf        tprintf
  209. #endif
  210.  
  211. /*  On 8-bit machines, the static type is as efficient as the register    */
  212. /*  type and far more efficient than the auto type.  On larger machines    */
  213. /*  such as the 8086 family, this is not necessarily the case.  To    */
  214. /*  let you experiment to see what generates the fastest, smallest code    */
  215. /*  for your machine, I have declared internal scratch variables in    */
  216. /*  functions "SCRATCH int", "SCRATCH unsigned", etc.  A SCRATCH    */
  217. /*  variable is made static below, but you might want to try register    */
  218. /*  instead.                                */
  219.  
  220. #define    SCRATCH        static
  221.  
  222. /*  A slow, but portable way of cracking an unsigned into its various    */
  223. /*  component parts:                            */
  224.  
  225. #define    clamp(u)    ((u) &= 0xffff)
  226. #define    high(u)        (((u) >> 8) & 0xff)
  227. #define    low(u)        ((u) & 0xff)
  228. #define    word(u)        ((u) & 0xffff)
  229.  
  230. /*  The longest source line the assembler can hold without exploding:    */
  231.  
  232. #define    MAXLINE        255
  233.  
  234. /*  The maximum number of source files that can be open simultaneously:    */
  235.  
  236. #define    FILES        4
  237.  
  238. /*  The fatal error messages generated by the assembler:        */
  239.  
  240. #define    ASMOPEN        "Source File Did Not Open"
  241. #define    ASMREAD        "Error Reading Source File"
  242. #define    DSKFULL        "Disk or Directory Full"
  243. #define    FLOFLOW        "File Stack Overflow"
  244. #define    HEXOPEN        "Object File Did Not Open"
  245. #define    IFOFLOW        "If Stack Overflow"
  246. #define    LSTOPEN        "Listing File Did Not Open"
  247. #define    NOASM        "No Source File Specified"
  248. #define    SYMBOLS        "Too Many Symbols"
  249.  
  250. /*  The warning messages generated by the assembler:            */
  251.  
  252. #define    BADOPT        "Illegal Option Ignored"
  253. #define    NOHEX        "-o Option Ignored -- No File Name"
  254. #define    NOLST        "-l Option Ignored -- No File Name"
  255. #define    TWOASM        "Extra Source File Ignored"
  256. #define    TWOHEX        "Extra Object File Ignored"
  257. #define    TWOLST        "Extra Listing File Ignored"
  258.  
  259. /*  Line assembler (AZ80.C) constants:                    */
  260.  
  261. #define    BIGINST        4        /*  longest instruction length    */
  262. #define    IFDEPTH        16        /*  maximum IF nesting level    */
  263. #define    NOP        0x00        /*  processor's NOP opcode    */
  264. #define    ON        1        /*  assembly turned on        */
  265. #define    OFF        -1        /*  assembly turned off        */
  266.  
  267. /*  Line assembler (AZ80.C) opcode attribute word flag masks:        */
  268.  
  269. #define    PSEUDO        0400    /*  is pseudo op            */
  270. #define    ISIF        0200    /*  is IF, ELSE, or ENDIF        */
  271.  
  272. /*  Line assembler (AZ80.C) pseudo-op opcode token values:        */
  273.  
  274. #define    DB        1
  275. #define    DC        2
  276. #define    DS        3
  277. #define    DW        4
  278. #define    ELSE        5
  279. #define    END        6
  280. #define    ENDIF        7
  281. #define    EQU        8
  282. #define    IF        9
  283. #define    INCL        10
  284. #define    ORG